import type { PluginOption } from 'vite'

export default function test(): PluginOption {
    return {
        name: 'vite-plugin-test',
        enforce: 'pre',
        config() {
            console.log('1>>>>>')
        },
        configureServer() {
            console.log('>>>>>2')
        },
        transformIndexHtml() {
            console.log('>>>>>3')
        },
        resolveId() {
            console.log('>>>>4')
        },
        load(path, options) {
            console.log('>>>>5')
            if (path.search('HelloWorld') >= 0) {
                return `
                <template>
                    <h1>内容被修改了</h1>
                </template>
                `
            }
        },
        transform(code, id, options) {
            console.log('>>>>6')
            if (code.search('内容被修改了') >= 0) {
                return {
                    code: code.replace('内容被修改了', '是的被修改了'),
                }
            }
            return {
                code,
            }
        },
    }
}
